<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <view class="jtop_c">项目概况</view>
      <view class="jtop_r" @tap="jshow_pop"
        ><image src="../../static/img/index/ic_ellipsis.png"></image
      ></view>
    </view>

    <view class="tophr"></view>

    <view class="addi" @tap="to_name">
      <text>项目名称</text>
      <input
        type="text"
        placeholder=""
        placeholder-style="color:#999999"
        disabled="true"
        :value="name"
        class="addi_cs ell"
      />
    </view>

    <view class="addi ">
      <view class="addbi" style="background:none">
        <text style="margin:0">项目所在地</text>
        <image src="../../static/img/jt.png" @confirm="confirm2"></image>
        <!-- <text class="addbir" >项目所在地</text> -->
        <view class="addi_cs">
          <pickerAddress
            @change="change"
            style="margin-top:22rpx"
            :defaultValue="txt"
            :class="[addi_cs, ell]"
          ></pickerAddress>
        </view>
      </view>
    </view>

    <view class="addb">
      <view class="addbi noborder" @tap="to_team">
        <text class="addbil">项目成员</text>
        <image src="../../static/img/jt.png"></image>
        <text class="addbir">{{ users.length }} 人</text>
      </view>
    </view>

    <view class="addb">
      <e-picker-plus
        endRule="2040-12-31"
        class="addbi"
        @confirm="confirm"
        mode="YMD"
      >
        <text class="addbil">项目开始时间</text>
        <image src="../../static/img/jt.png" @confirm="confirm"></image>
        <text class="addbir" @confirm="confirm">{{ beginDate }}</text>
      </e-picker-plus>
      <e-picker-plus
        endRule="2040-12-31"
        class="addbi"
        @confirm="confirm2"
        mode="YMD"
      >
        <text class="addbil">项目结束时间</text>
        <image src="../../static/img/jt.png" @confirm="confirm2"></image>
        <text class="addbir" @confirm="confirm2">{{ endDate }}</text>
      </e-picker-plus>
    </view>

    <view class="addi" @tap="to_dsc">
      <text>项目描述</text>
      <textarea
        auto-height="true"
        style="min-height: 150rpx;"
        maxlength="-1"
        placeholder-style="color:#999999"
        :value="descn"
        placeholder="无"
        disabled="true"
      />
    </view>

    <!-- 弹出层 -->
    <view :class="[ashowpop ? 'tc' : 'tc hide']">
      <view class="jtop_bj" @click="jshow_pop"></view>

      <view class="tc_fbox">
        <view class="tc_fbox_bt2" @click="jdelete">
          删除项目
        </view>
        <view class="tc_fbox_bt" @click="jshow_pop">
          取消
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import pickerAddress from 'components/biaofun-region/biaofun-region.vue';
import biaofunDatetimePicker from '@/components/biaofun-datetime-picker/biaofun-datetime-picker.vue';

import { mapState } from 'vuex';

export default {
  components: {
    biaofunDatetimePicker,
    pickerAddress,
  },

  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
  /**
   * 页面数据
   */

  data() {
    return {
      repeat_click: true,
      ashowpop: false,
      defaultValue: '', // 默认值
      beginDate: '',
      descn: '',
      endDate: '',
      name: '',
      users: '',

      txt: [],
      txtid: [],
      dqfull_name: uni.getStorageSync('dqfull_name'),
    };
  },
  onLoad(e) {
    console.log('onLoad:', e);

    this.id = this.dqfull_name.id;

    request({
      url: '/ucenter/project-user/list',
      data: {
        projectId: this.id,
      },

      method: 'GET',
      success: openIdRes => {
        console.log('openIdRes', openIdRes);
        if (openIdRes.data.success == true) {
          // uni.navigateBack()
        } else {
          this.repeat_click = true;
          uni.showToast({
            title: openIdRes.data.msg,
            icon: 'none',
          });
          this.isLoading = false;
        }
      },
      fail: () => {
        this.repeat_click = true;
        uni.showToast({
          title: '服务器开小差，请稍后~',
          icon: 'none',
        });
        return false;
      },
    });
  },

  onShow() {
    // 获取用户信息
    request({
      url: '/ucenter/project/' + this.id,
      method: 'GET',

      success: res => {
        console.log('项目详情', res.data.data);

        // 已经授权了、查询到用户的数据了
        if (res.data.success == true) {
          this.beginDate = res.data.data.beginDate;
          this.descn = res.data.data.descn;
          this.endDate = res.data.data.endDate;
          this.name = res.data.data.name;

          if (res.data.data.users) {
            this.users = res.data.data.users;
          }

          this.txt = [
            res.data.data.provinceName,
            res.data.data.cityName,
            res.data.data.districtName,
          ];
        } else {
          // 错误
          this.repeat_click = true;
          uni.showToast({
            title: res.data.msg,
            icon: 'none',
          });
        }
      },
    });

    // 获取用户信息
    request({
      url: '/ucenter/project-user-role/' + this.id,
      method: 'GET',

      success: res => {
        console.log('项目详情22', res.data);

        // 已经授权了、查询到用户的数据了
        if (res.data.success == true) {
          // this.name = res.data.data.name;
          if (res.data.data) {
            this.users = res.data.data;
          }
        } else {
          // 错误
          this.repeat_click = true;
          uni.showToast({
            title: res.data.msg,
            icon: 'none',
          });
        }
      },
    });
  },

  methods: {
    change(data) {
      console.log(data);
      this.txt = [data[0].name, data[1].name, data[2].name];
      this.txtid = [data[0].id, data[1].id, data[2].id];

      console.log('txt', this.txt);
      console.log('txt', this.txtid);
      this.define();
      // this.txt = data.data.join('')
      // console.log(data.data.join(''))
    },

    confirm(e) {
      console.log(e);
      this.beginDate = e.result;
      this.define();
    },

    confirm2(e) {
      console.log(e);
      this.endDate = e.result;
      this.define();
    },

    define() {
      request({
        url: '/ucenter/project/' + this.id,
        data: {
          name: this.name,
          descn: this.dsc,
          beginDate: this.beginDate,
          endDate: this.endDate,
          provinceId: this.txtid[0],
          cityId: this.txtid[1],
          districtId: this.txtid[2],
        },

        method: 'PUT',
        success: openIdRes => {
          console.log(openIdRes);
          if (openIdRes.data.success == true) {
            wx.showToast({
              title: '修改成功',
              icon: 'none',
              duration: 1500,
              success: function() {
                setTimeout(function() {
                  uni.navigateBack();
                }, 1500);
              },
            });

            // uni.navigateBack()
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: openIdRes.data.msg,
              icon: 'none',
            });
            this.isLoading = false;
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    jdelete() {
      var aa = this.id;
      request({
        url: '/passport/v1/project/' + aa,
        method: 'DELETE',

        success: res => {
          if (res.data.success == true) {
            this.ashowpop = false;
            uni.removeStorageSync('dqfull_name');
            wx.showToast({
              title: '删除成功',
              icon: 'none',
              duration: 1500,
              success: function() {
                setTimeout(function() {
                  uni.navigateBack();
                }, 1500);
              },
            });
          } else {
            // 错误
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    to_dsc() {
      uni.navigateTo({
        url:
          '../main/project_dsc?id=' +
          this.id +
          '&dsc=' +
          this.descn +
          '&name=' +
          this.name +
          '&endDate=' +
          this.endDate +
          '&beginDate=' +
          this.beginDate,
      });
    },
    to_name() {
      uni.navigateTo({
        url:
          '../main/project_name?id=' +
          this.id +
          '&dsc=' +
          this.descn +
          '&name=' +
          this.name +
          '&endDate=' +
          this.endDate +
          '&beginDate=' +
          this.beginDate,
      });
    },
    to_team() {
      uni.navigateTo({
        url:
          '../main/project_team?id=' +
          this.id +
          '&dsc=' +
          this.descn +
          '&name=' +
          this.name +
          '&endDate=' +
          this.endDate +
          '&beginDate=' +
          this.beginDate,
      });
    },
    jshow_pop() {
      this.ashowpop = !this.ashowpop;
    },
    /**
     * 确认选择日期时间
     * @param {Object} date 日期数据
     */
    changeDatetimePicker(date) {
      console.log('选择的日期时间数据：', date);
    },
    navigateBack() {
      uni.navigateBack();
    },
  },
};
</script>

<style>
.tophr {
  width: 100%;
  height: 88rpx;
}
.addi {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  box-shadow: inset 0px 1px 0px #dddddd, inset 0px -1px 0px #dddddd;
  margin: 20rpx 0 0;
}
.addi text {
  width: auto;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
  margin: 0 0 0 30rpx;
}
.addi input {
  width: auto;
  height: 50rpx;
  display: block;
  float: right;
  margin: 20rpx 30rpx 0 0;
  text-align: right;
  line-height: 50rpx;
  font-size: 34rpx;
  color: #999999;
}
.addb {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  margin: 20rpx 0 0;
}
.addbi {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: 90rpx;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
}
.addb .addbi:last-child {
  border: none;
}
.addbi .addbil {
  width: auto;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
}
.addbi .addbir {
  width: auto;
  height: 90rpx;
  display: block;
  float: right;
  line-height: 90rpx;
  font-size: 32rpx;
  color: #999999;
}
.addbi image {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 33rpx 30rpx 0 30rpx;
}
.addi textarea {
  width: 690rpx;
  height: 150rpx;
  display: block;
  float: left;
  margin: 0rpx 30rpx 20rpx;
  text-align: left;
  line-height: 40rpx;
  font-size: 34rpx;
  color: #999999;
}
.jhead_portrait {
  width: 690rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0rpx 30rpx 20rpx;
}
.jhead_portrait image {
  width: 84rpx;
  height: 84rpx;
  display: block;
  float: left;
  margin: 0rpx 20rpx 20rpx 0rpx;
  border-radius: 6rpx;
}
.addbi .addbir .datatime,
.addbi .addbir .datatime .uni-picker-container {
  min-width: 200rpx;
  height: 90rpx;
  display: block;
  float: right;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_r {
  width: auto;
  height: 88rpx;
  display: block;
  float: right;
  margin: 0rpx 20rpx 0 0;
  line-height: 88rpx;
  font-size: 32rpx;
  color: #000000;
  color: #256aff;
  opacity: 0.5;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
}

.jtop_bs {
  width: 100%;
  height: auto;
  background: #ffffff;
  display: block;
  float: left;
}
.jtop_bs view {
  width: 720rpx;
  height: 90rpx;
  background: #ffffff;
  display: block;
  float: left;
  margin: 0 0 0 30rpx;
  border-bottom: 1px solid #dddddd;
}
.jtop_bs view text {
  width: 80%;
  height: 90rpx;
  line-height: 90rpx;
  background: #ffffff;
  display: block;
  float: left;
  font-size: 34rpx;
  color: #000000;
}
.jtop_bs view image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 21rpx 30rpx 0 0;
}
.jtop_tc {
  display: none;
}

.jtop_r {
  width: auto;
  height: 88rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
  line-height: 88rpx;
  font-size: 32rpx;
  color: #000000;
  color: #256aff;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}

.tc {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  display: block;
}
.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
}
.tc_fbox_bt {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 20rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #f2f2f2;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10001;
}
.tc_fbox_bt2 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: red;
  border-top: 0rpx solid #f2f2f2;
  background: #ffffff;
}
.addi_cs {
  width: 400rpx;
  float: right;
}

.uni-input-input {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
</style>
